﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Shop.Infrastructure.Paged
{
    [Serializable]
    public class PagedBase : IPaged
    {
        /// <summary>
        /// 只为了序列化
        /// </summary>
        public PagedBase()
        {
        }

        public PagedBase(int pageIndex, int pageSize, int totalCount)
        {
            this.PageSize = pageSize;
            this.PageIndex = pageIndex;
            this.TotalCount = totalCount;
        }

        public int PageIndex
        {
            get;
            set;
        }

        public int PageSize
        {
            get;
            set;
        }

        public int TotalCount
        {
            get;
            set;
        }

        public int TotalPages
        {
            get
            {
                if (this.PageSize == 0)
                {
                    return 1;
                }
                int totalPages = this.TotalCount / this.PageSize;
                if (this.TotalCount % this.PageSize > 0)
                    totalPages++;
                return totalPages;
            }
        }

        public bool HasPreviousPage
        {
            get
            {
                return (PageIndex > 0);
            }
        }
        public bool HasNextPage
        {
            get
            {
                return (PageIndex + 1 < TotalPages);
            }
        }
    }
}
